%%%-----------------------------------
%%% @Module  : pt_11
%%% @Author  : kxp
%%% @Created : 2016.08.11
%%% @Description: 10帐户信息
%%%-----------------------------------
-module(pt_11).
-export([read/2, write/2,time_to_string/1]).
-include("common.hrl").
-include("proto_all.hrl").

%%
%%客户端 -> 服务端 ----------------------------
%%

%%11000请求玩家信息
read(11000, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_player_info, Bin),	
	{c2s_player_info ,Playerid} = ClientData,
    {ok, [Playerid]};

%%11002玩家修改性别
read(11002, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_change_sex, Bin),	
	{c2s_change_sex ,Sex} = ClientData,
    {ok, [Sex]};

%%11003玩家修改游戏名
read(11003, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_change_nick, Bin),	
	{c2s_change_nick ,Nick} = ClientData,
    {ok, [Nick]};

%% 11007 更改玩家头像
read(11007, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_change_facelook, Bin),
	{c2s_change_facelook, IconId} = ClientData,
	{ok, [IconId]};

%% 获取头像列表
read(11008, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_get_facelook_list, Bin),
	{c2s_get_facelook_list, UID} = ClientData,
	{ok, [UID]};

%% 获取会员信息
read(11010, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_vip_info, Bin),
	{c2s_vip_info, UID} = ClientData,
	{ok, [UID]};

%% 11011 获取斗地主超级加倍剩余次数
read(11011, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_get_super_time, Bin),
	{c2s_get_super_time, UID} = ClientData,
	{ok, [UID]};

%% 11012 完成新手引导
read(11012, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_finish_newbie_guide, Bin),
    {c2s_finish_newbie_guide, UId} = ClientData,
    {ok, [UId]};

%% 11013 UI热点
read(11013, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_record_hotpoint, Bin),
    {c2s_record_hotpoint, HotPoint} = ClientData,
    {ok, [HotPoint]};

%% 11015 领取vip奖励
read(11015, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_vip_reward, Bin),
    {c2s_get_vip_reward, UID, VipID} = ClientData,
    {ok, [UID, VipID]};

%% 11017 记录玩家活动点击
read(11017, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_record_acty_click, Bin),
    {c2s_record_acty_click, ActyId} = ClientData,
    {ok, [ActyId]};

%% 11019 ios内购充值
read(11019, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_ios_inn_pay, Bin),
	{c2s_ios_inn_pay, UID, RechargedID, ProductID, PayAmount, OrderNote} = ClientData,
	{ok, [UID, RechargedID, ProductID, PayAmount, OrderNote]};

%% 11022 获取玩家面板信息
read(11022, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_player_board_info, Bin),
    {c2s_get_player_board_info, TargetId} = ClientData,
    {ok, [TargetId]};

%% 11026 个性签名
read(11026, Bin) ->
	%%io:format("~n===11023==Bin:~p==~n", [Bin]),
    {ClientData, _} = proto_read:unpack(c2s_player_signature, Bin),    
    {c2s_player_signature, UID, Signature} = ClientData,
    {ok, [UID, Signature]};

%% 11027 完成百人牛牛引导
read(11027, Bin) ->
	%%io:format("~n===11023==Bin:~p==~n", [Bin]),
    {ClientData, _} = proto_read:unpack(c2s_finish_hundred_douniu_guide, Bin),    
    {c2s_finish_hundred_douniu_guide, UID, State} = ClientData,
    {ok, [UID, State]};

%% 11028 查询新手引导状态
read(11028, Bin) ->
	%%io:format("~n===11023==Bin:~p==~n", [Bin]),
    {ClientData, _} = proto_read:unpack(c2s_newbie_guide_state, Bin),    
    {c2s_newbie_guide_state, UID} = ClientData,
    {ok, [UID]};

%% 11029 查询大厅在线
read(11029, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_game_hall_info, Bin),    
    {ok, [ClientData]};

%% 11030 充值通知
read(11030, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_recharge_notify, Bin),    
    {ok, [ClientData]};

%% 11031 获取玩家净胜分
read(11031, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_player_win_lose, Bin),   
	{c2s_player_win_lose, UID} = ClientData,
    {ok, [UID]};

%% 11032 玩家子游戏参与
read(11032, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_player_subgame_info, Bin),   
    {c2s_player_subgame_info, SubID} = ClientData,
    {ok, [SubID]};

%% 11033 玩家剩余次数
read(11033, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_player_limit_times, Bin),
    {c2s_player_limit_times, UID} = ClientData,
    {ok, [UID]};

%% 11034 玩家实名认证
read(11034, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_player_real_auth, Bin),
    {c2s_player_real_auth, UID} = ClientData,
    {ok, [UID]};

%% 11035 举报玩家
read(11035, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_report_player, Bin),
    {c2s_report_player, UID, ReportReasonList, Phone} = ClientData,
    {ok, [UID, ReportReasonList, Phone]};

read(_Cmd, _R) ->
    ?ERROR_MSG("~s pt_10 reading cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), _Cmd, _R]),
    {error, no_match}.

%%
%%服务端 -> 客户端 ------------------------------------
%%

%%玩家信息
write(11000, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_info, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11000, ServerData)};

%%玩家金币和红卡信息变动
write(11001, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_coin_redcard, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11001, ServerData)};

%%玩家修改性别
write(11002, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_change_sex, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11002, ServerData)};

%%玩家修改游戏名
write(11003, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_change_nick, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11003, ServerData)};

%% 更换头像
write(11007, [Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_change_facelook, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(11007, ServerData)};

%% 获取头像列表
write(11008, [Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_get_facelook_list, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(11008, ServerData)};

%% 推送玩家所在子游戏
write(11009, [Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_notify_player_in_game, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(11009, ServerData)};

%% 获取会员信息
write(11010, [Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_vip_info, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(11010, ServerData)};

%% 11011 获取斗地主超级加倍剩余次数
write(11011, [Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_get_super_time, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(11011, ServerData)};

%% 11012 完成新手引导
write(11012, [Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_finish_newbie_guide, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(11012, ServerData)};

%% 11014 通知玩家系统限制
write(11014, [Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_player_system_limit, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(11014, ServerData)};

%% 11015 领取vip奖励
write(11015, [Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_get_vip_reward, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(11015, ServerData)};

%% 11016 vip赠送金币
write(11016, [Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_vip_send_coin, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(11016, ServerData)};

%% 11017 记录玩家活动点击
write(11017, [Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_record_acty_click, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(11017, ServerData)};

%% 11018 通知玩家新功能开启
write(11018, [Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_open_new_system, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(11018, ServerData)};
 
 
%% 11019 ios内购充值
write(11019, [Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_ios_inn_pay, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(11019, ServerData)};

%% 11020 版本更新奖励推送通知
write(11020, [Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_update_version_reward, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(11020, ServerData)};


%% 11022 获取玩家面板信息
write(11022, [Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_get_player_board_info, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(11022, ServerData)};

%% 11023 福袋免费抽奖次数
write(11023, [Seq, RecordData]) ->
	%%io:format("~n===11023==RecordData:~p==~n", [RecordData]),
	MsgPack = proto_write:pack(s2c_box_draw_free_times, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
	{ok, pt:pack(11023, ServerData)};

%% 玩家属性变更
write(11024, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_attr_infos, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11024, ServerData)};

%% 玩家属性变更
write(11025, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_attrs_infos, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11025, ServerData)};

%% 个性签名
write(11026, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_signature, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11026, ServerData)};

%% 完成百人牛牛引导
write(11027, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_finish_hundred_douniu_guide, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11027, ServerData)};

%% 新手引导状态是否激活
write(11028, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_newbie_guide_state, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11028, ServerData)};

%% 大厅在线
write(11029, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_game_hall_info, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11029, ServerData)};

write(11030, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_recharge_notify, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11030, ServerData)};

%% 每日净胜分
write(11031, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_win_lose, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11031, ServerData)};

%% 子游戏参与
write(11032, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_subgame_info, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11032, ServerData)};

%% 11033 获取玩家剩余次数
write(11033, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_limit_times, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11033, ServerData)};

%% 11034 玩家实名认证
write(11034, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_real_auth, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11034, ServerData)};

%% 11035 举报玩家
write(11035, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_report_player, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(11035, ServerData)};

write(Cmd, _R) ->
    ?ERROR_MSG("~s pt_11 writting cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), Cmd, _R]),
    {ok, pt:pack(0, <<>>)}.

time_to_string(Time) ->
	{{_Year, Month, Day},{Hour, M, _S}} = util:seconds_to_localtime(Time),
	Content = io_lib:format("~2..0w月~2..0w日~2..0w:~2..0w",[Month, Day, Hour, M]),
	Content.
	
